package treeset;

import java.util.Comparator;
import java.util.TreeSet;

public class MyTreeSet1 {
    public static void main(String[] args) {
        TreeSet<Teacher>list = new TreeSet<>(new Comparator<Teacher>() {
            @Override
            public int compare(Teacher o1, Teacher o2) {
                int i = o1.getAge() - o2.getAge();
                i = i == 0 ? o1.getName().compareTo(o2.getName()) : i;
                return i;
            }
        });
        Teacher t1 = new Teacher("zhangsang",18);
        Teacher t2 = new Teacher("lisi",30);
        Teacher t3 = new Teacher("wanwu",28);
        list.add(t1);
        list.add(t2);
        list.add(t3);
        System.out.println(list);
    }
}
